package com.minelx.tableui.launch;

import com.minelx.landisk.filesystem.Paths;
import com.minelx.table.core.Table;
import com.minelx.table.core.Tables;
import com.minelx.tableui.common.Chooser;
import com.minelx.tableui.form.PreviewForm;

import java.io.IOException;
import java.nio.charset.Charset;

import static com.minelx.landisk.filesystem.core.init.OpenPolicy.useExisting;

public class OpenWithFileLauncher {
	public static void main(String[] args) throws IOException {
		if (args.length != 1) {
			throw new IllegalArgumentException("args.length should be 1, or not: " + args.length);
		}

		// do job
		String path = args[0].replace("\\", "/");
		Table table = Tables.csv(Paths.of(path, useExisting()).read(Chooser.chooseCharset()));
		new PreviewForm(table, Paths.projectRoot()).setVisible(true);
	}
}
